<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<%-- <%@include file="edit.jsp"%> --%>
<html>
<head>
<script type="text/javascript">
	formatterDate = function (date) {
		var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
		var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0"
		+ (date.getMonth() + 1);
		var hor = date.getHours();
		var min = date.getMinutes();
		var sec = date.getSeconds();
		return date.getFullYear() + '-' + month + '-' + day+" "+hor+":"+min+":"+sec;
	};
	
	var startDt = formatterDate(new Date('${item.startDt}'));
	var endDt = formatterDate(new Date('${item.endDt}'));
	$(function() {
		$('#startDt').datetimebox('setValue',  startDt);
		$('#endDt').datetimebox('setValue', endDt);
		
		$('#enabled').radiobox({name:'entity.enabled',value:true,data:[[true,'有效'],[false,'无效']]});
		$('#toolbar').toolbar({buttons:[
			{name:'save',iconCls:'icon-save',text:'保存'}
	  	],handler:handler});
		
		
	});
	function handler() {
		switch(this.name) {
			case 'save': toSave();break;
		}
	}
	function toSave(){
		var isValid = $('#dataform').form('enableValidation').form('validate');
		var tip = $("#td_article_showTip").html("");
		var link = $("#entity_link").val();
		if(link.length<1){
			var div_tip = '<span style="color: red;">请添加广告链接</span>';
			tip.append(div_tip);
			isValid = isValid && false;
			return;
		}
		var imgurl = $("#imgurl").val();
		if(imgurl.length<1){
			var div_tip = '<span style="color: red;">请上传封面图片</span>';
			tip.append(div_tip);
			isValid = isValid && false;
			return;
		}
		if(isValid){
			$.messager.progress({title:'系统提示',text:'数据处理中，请耐心等待...'});
			$.submit('#dataform',function(r) {
				$.messager.progress('close');
				if(r.code<0) return $alert(r.msg);
				top.$prompt('保存成功');
				top.$window.close(window,1,null);
			});
		}
	}
	
	function toDeploy(){
		showUpload({title:'上传封面'
			,options:{
				filters:{
					mime_types: [{title : "封面图片", extensions : "jpg,png"}]
				},
				multi_selection: false ,
				 init:{
					 FileUploaded:function(uploader,file,responseObject){
						 var response = responseObject.response;
						 var json = eval('(' + response + ')');
						 var data = json.data;
						 var path = data.fileUrl;
						 $("#imgurl").val(path);
						 showImg(path);
					 }
				},
				complete:function(){
					top.$ok('上传成功');
				}
			}
		});
	}
	function showImg(path){
		$("#img_show").attr("src",path);
	}
	function searchByitem(){
		var searchItem = {};
		searchItem.articleTitle = $("#article_title").textbox("getValue");
		searchItem.userName = $("#article_user").textbox("getValue");
		searchItem.articleType = $("#article_type").combobox("getValue");
		$('#article_datagrid').datagrid({ queryParams: searchItem,url:"/article/info/searchByUserAndTitleAndType"});   //点击搜索
	}
	function setSelect(index,row){
		var link = "id:"+row.id+"  作者:"+row.userName+"  标题:"+row.articleTitle;
		$("#link_show").textbox('setValue', link);
		$("#entity_link").val(row.id);
	}
	
</script>
</head>
<body>
	<div id="toolbar" class="toolbar" ></div>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'center',border:false" style="height:300px;">
			<form id="dataform" action="edit" method="POST">
				<input type="hidden" name="entity.id" value="${item.id }">
				<input type="hidden" name="entity.enabled" value="${item.enabled}">
				<input type="hidden" name="entity.targetplace" value="1">
				<table cellpadding="5" style="width:100%;">
					<tr>
						<td style="width:20%;">作者桌面标题:</td>
						<td style="width:80%;">
							<input class="easyui-textbox" value="${item.title }" name="entity.title" data-options="required:true"/>
						</td>
					</tr>
					<tr style="display: none;">
						<td>广告类型:</td>
						<td>
							<input id="type" value="5" name="entity.type">
						</td>
					</tr>
					<tr>
						<td>开始时间:</td>
						<td>
							<input class="easyui-datetimebox" value="${item.startDt }" name="entity.startDt" >
						</td>
					</tr>
					<tr>
						<td>结束时间:</td>
						<td>
							<input class="easyui-datetimebox" value="${item.endDt }" name="entity.endDt" >
						</td>
					</tr>
					<tr>
						<td>广告图片:</td>
						<td>
							<input type="button" value="上传" onclick="toDeploy()">
						</td>
					</tr>
					<tr>
						<td></td>
						<td >
							<input id="imgurl" name="entity.imgurl" type="hidden" value="${item.imgurl }">
							<img id="img_show" alt="广告图片" src="${item.imgurl }" style="width: 80px;height: 80px;">
						</td>
					</tr>
					<tr>
						<td>广告描述:</td>
						<td>
							<input value="${item.description }" class="easyui-textbox" name="entity.description" data-options="multiline:true" style="height:100px;width:100%;"/>
						</td>
					</tr>
					<tr>
						<td>选择大咖:</td>
						<td>
							<input id="entity_link" class="easyui-combogrid" value="${item.link}" name="entity.link" style="width:250px" data-options="
								panelWidth: 500,
								idField: 'id',
								textField: 'nickname',
								url: '/degua/project/detail/adminUserPage',
								method: 'post',
								columns: [[
									{field:'id',title:'id',width:80},
									{field:'nickname',title:'昵称',width:120},
									{field:'username',title:'用户名',width:120,align:'right'},
									{field:'phoneNumber',title:'手机号码',width:150,align:'right'},
									{field:'point',title:'积分',width:60,align:'center'},
									{field:'email',title:'邮箱',width:60,align:'center'}
								]],
								fitColumns: true
							"/>
						</td>
					</tr>
					<tr class="form-tr">
						<th class="form-th">提示:</th>
						<td class="form-td" id="td_article_showTip">
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>